<!--Copyright (C) Kherty.  All rights reserved.-->
<oui:GroupPanel
  x:Class="OpenLS.Spreadsheet.UI.HomeTabContent"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:oui="http://schemas.Kherty.com/office/2007"
  xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI"
  xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet"
    xmlns:drawing2="clr-namespace:OpenLS.Drawing.UI;assembly=OpenLS.Drawing.UI"
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals"
    xmlns:Core="clr-namespace:OpenLS.Core;assembly=OpenLS.Core"
    xmlns:Internals1="clr-namespace:OpenLS.Drawing.UI.Internals;assembly=OpenLS.Drawing.UI"
    xmlns:media="clr-namespace:OpenLS.Media;assembly=OpenLS.Media"
    xmlns:Internals2="clr-namespace:OpenLS.UI.Internals;assembly=OpenLS.UI"
  xmlns:Resources="clr-namespace:OpenLS.Spreadsheet.UI.Internals.Resources"
  DataContext="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.Worksheet)}"
    >
    <oui:GroupPanel.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ssui:CellStyleResources/>
                <Internals:ColorResources />
                <ssui:TableStyleResources />
                <oui:ButtonGroupResources />
                <oui:MenuResources/>
            </ResourceDictionary.MergedDictionaries>
            <GroupStyle HidesIfEmpty="False" x:Key="groupStyle">
                <GroupStyle.HeaderTemplate>
                    <HierarchicalDataTemplate DataType="{x:Type CollectionViewGroup}">
                        <Border BorderThickness="0 0 0 1" BorderBrush="#FFC5C5C5">
                            <TextBlock Text="{Binding Name}" Background="#FFDDE7EE" FontWeight="Bold"/>
                        </Border>
                    </HierarchicalDataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
            <DataTemplate DataType="{x:Type drawing2:FontFamilyGroup}">
                <Border BorderThickness="0 0 0 1" BorderBrush="#FFC5C5C5">
                    <TextBlock Text="{Binding Name}" Background="#FFDDE7EE" FontWeight="Bold" Foreground="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"/>
                </Border>
            </DataTemplate>
        </ResourceDictionary>
    </oui:GroupPanel.Resources>
    <oui:Group DockPanel.Dock="Left"  SnapsToDevicePixels="True"
               Header="{x:Static Internals2:UIStringTable.Clipboard}" MediumStatePriority="1" CollapsedStatePriority="Never">
        <Menu Margin="4">
            <MenuItem Command="{x:Static ApplicationCommands.Paste}" ToolTip="Paste the contents of the clipboard"  Icon="{media:Image Paste}" >
                <!-- loc-->
                <MenuItem Command="{x:Static ssui:ClipboardCommands.PasteValues}" />
                <MenuItem Command="{x:Static ssui:ClipboardCommands.PasteFormulas}" />
                <MenuItem Command="{x:Static ssui:ClipboardCommands.PasteTranspose}" />
                <MenuItem Command="{x:Static ssui:ClipboardCommands.PasteSpecial}" />
                <MenuItem Command="{x:Static ssui:ClipboardCommands.PasteAsPicture}" />
                <MenuItem Command="{x:Static ssui:ClipboardCommands.PasteNoBorders}" />
            </MenuItem>
        </Menu>

        <StackPanel oui:RibbonElement.ControlState="Medium" oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}">
            <Button Command="{x:Static ApplicationCommands.Cut}"/>
            <Button Command="{x:Static ApplicationCommands.Copy}"/>
            <Button Command="{x:Static ssui:ClipboardCommands.FormatPainter}"/>
        </StackPanel>
    </oui:Group>
    <oui:Group DockPanel.Dock="Left" Header="{x:Static Internals2:UIStringTable.Font}"
               Command="{x:Static ssui:SpreadsheetCommands.FormatCells}" CommandParameter="Font"
               MediumStatePriority="10" CollapsedStatePriority="16">
        <oui:FlowPanel VerticalAlignment="Center" oui:RibbonElement.MediumGroupStyle="{x:Static oui:FlowPanel.NoMarginStyle}">
            <ComboBox 
            ItemsSource="{Binding Path=Workbook.Theme, Converter={x:Static Internals1:DrawingConverters.ThemeToGroupedFontsConverter}}"
          VerticalAlignment ="Center"  
          SelectedItem="{Binding Selection.FontFamily}" 
          oui:HighlightElement.HighlightedItemChanged="onFontFamilyPreviewChanged" Width="80"
          SelectionChanged="onFontFamilyChanged" Style="{x:Static drawing2:Styles.FontFamilyComboBoxStyle}" >
            </ComboBox>
            <ComboBox Foreground="Black" VerticalAlignment ="Center"  MinWidth="39" ItemsSource ="{x:Static oui:FontHelper.FontSizes}"
                  Focusable="False" SelectionChanged="onFontSizeChanged" oui:HighlightElement.HighlightedItemChanged="onFontSizePreviewChanged"
                SelectedItem="{Binding Selection.FontSize}"/>
            <oui:Box>
                <!--<Button>a</Button> -->
                <Button Command="{x:Static EditingCommands.IncreaseFontSize}">
                    <Grid>
                        <TextBlock FontSize="11" FontFamily="Times" FontWeight="Bold">A</TextBlock>
                        <Path VerticalAlignment="Top" Margin="6 3 0 0"  HorizontalAlignment="Right" Fill ="Blue" Data="M 0,0 L 6,0 L 3,-2 L 0,0"/>
                    </Grid>
                </Button>
                <Button Command="{x:Static EditingCommands.DecreaseFontSize}">
                    <Grid>
                        <TextBlock FontSize="9" FontFamily="Times" >A</TextBlock>
                        <Path VerticalAlignment="Top" Margin="6 3 0 0" HorizontalAlignment="Right" Fill ="Blue" Data="M 0,0 L 6,0 L 3,2 L 0,0"/>
                    </Grid>
                </Button>
            </oui:Box>
            <oui:Box>
                <ToggleButton Command="{x:Static EditingCommands.ToggleBold}" IsChecked="{Binding Path=Selection.FontWeight, Converter={x:Static Internals:SpreadsheetConverters.IsBold}, Mode=TwoWay}">
                    <TextBlock FontWeight='UltraBold' FontStretch="Expanded" FontFamily="Times New Roman" TextElement.FontSize='12' Text="{x:Static Resources:UIStringTable.BoldSymbol}" VerticalAlignment="Center" />
                </ToggleButton>
                <ToggleButton Command="{x:Static EditingCommands.ToggleItalic}" IsChecked="{Binding Path=Selection.FontStyle, Converter={x:Static Internals:SpreadsheetConverters.IsItalic}, Mode=TwoWay}">
                    <TextBlock FontWeight='UltraBold' FontStretch="Expanded" FontStyle="Oblique" FontFamily="Times New Roman" TextElement.FontSize='12' Text="{x:Static Resources:UIStringTable.ItalicSymbol}" VerticalAlignment="Center" />
                </ToggleButton>
                <Menu>
                    <MenuItem Command="{x:Static EditingCommands.ToggleUnderline}" Tag="Small"
                      IsChecked="{Binding Path=Selection.FontUnderline, Converter={x:Static Internals:SpreadsheetConverters.IsSingleConverter}, Mode=TwoWay}">
                        <MenuItem.Header>
                            <Underline FontFamily="Times New Roman" TextElement.FontSize='12' >
                                <Run Text="{x:Static Resources:UIStringTable.UnderlineSymbol}"/>
                            </Underline>
                        </MenuItem.Header>
                        <MenuItem Command="{x:Static EditingCommands.ToggleUnderline}"
      IsChecked="{Binding Path=Selection.FontUnderline, Converter={x:Static Internals:SpreadsheetConverters.IsSingleConverter}, Mode=TwoWay}">
                            <MenuItem.Header>
                                <Underline FontFamily="Times New Roman" TextElement.FontSize='12'>
                                    <Run Text="{x:Static Resources:UIStringTable.UnderlineSymbol}"/>
                                </Underline>
                            </MenuItem.Header>
                        </MenuItem>
                        <MenuItem Command="{x:Static EditingCommands.ToggleUnderline}"
                            CommandParameter="{x:Static ss:UnderlineType.Double}"
                            IsChecked="{Binding Path=Selection.FontUnderline, Converter={x:Static Internals:SpreadsheetConverters.IsDoubleConverter}, Mode=TwoWay}">
                            <!--<Underline FontFamily="Times New Roman" TextElement.FontSize='12'>D</Underline> -->
                            <MenuItem.Header>
                                <TextBlock Text='{x:Static Resources:UIStringTable.DoubleUnderlineSymbol}'>
                    <TextBlock.TextDecorations>
                      <TextDecoration PenOffset='0'/>
                      <TextDecoration PenOffset='2'/>
                    </TextBlock.TextDecorations>
                                </TextBlock>
                            </MenuItem.Header>
                        </MenuItem>

                    </MenuItem>
                </Menu>
            </oui:Box>
            <Menu Height="22" >
                <MenuItem Tag="Small" Height="23" oui:RibbonElement.Icon="{media:SmallImage BordersBottom}">
                    <MenuItem Command="{x:Static ssui:BorderCommands.SetBottomBorder}" oui:RibbonElement.Icon="{media:SmallImage BordersBottom}"/>
                    <MenuItem Command="{x:Static ssui:BorderCommands.SetTopBorder}" oui:RibbonElement.Icon="{media:SmallImage BordersTop}"/>
                    <MenuItem Command="{x:Static ssui:BorderCommands.SetLeftBorder}" oui:RibbonElement.Icon="{media:SmallImage BordersLeft}"/>
                    <MenuItem Command="{x:Static ssui:BorderCommands.SetRightBorder}" oui:RibbonElement.Icon="{media:SmallImage BordersRight}"/>
                    <Separator/>
                    <MenuItem Command="{x:Static ssui:BorderCommands.ClearBorders}" oui:RibbonElement.Icon="{media:SmallImage BordersNone}"/>
                    <MenuItem Command="{x:Static ssui:BorderCommands.SetAllBorders}" oui:RibbonElement.Icon="{media:SmallImage BordersAll}" />
                    <MenuItem Command="{x:Static ssui:BorderCommands.SetOutsideBorders}" oui:RibbonElement.Icon="{media:SmallImage BordersOutside}"/>
                    <MenuItem Header="{x:Static Resources:UIStringTable.ThickBoxBorders}"  oui:RibbonElement.Icon="{media:SmallImage BordersOutsideThick}" 
                              Command="{x:Static ssui:BorderCommands.SetOutsideBorders}" 
                              CommandParameter="{x:Static ss:BorderStyle.Thick}" />
                    <Separator/>
                    <MenuItem Header="{x:Static Resources:UIStringTable.BottomDoubleBorder}" oui:RibbonElement.Icon="{media:SmallImage BordersBottomDouble}" Command="{x:Static ssui:BorderCommands.SetBottomBorder}" CommandParameter="{x:Static ss:BorderStyle.Double}" />
                    <MenuItem Header="{x:Static Resources:UIStringTable.ThickBottomBorder}" oui:RibbonElement.Icon="{media:SmallImage BordersBottomThick}" Command="{x:Static ssui:BorderCommands.SetBottomBorder}" CommandParameter="{x:Static ss:BorderStyle.Thick}" />
                    <MenuItem Command="{x:Static ssui:BorderCommands.SetTopAndBottomBorders}" oui:RibbonElement.Icon="{media:SmallImage BordersTopBottom}"/>
                    <MenuItem Header="{x:Static Resources:UIStringTable.TopAndBottomThickBorder}"  oui:RibbonElement.Icon="{media:SmallImage BordersTopBottomThick}" Command="{x:Static ssui:BorderCommands.SetTopAndBottomBorders}" CommandParameter="{x:Static ss:BorderStyle.Thick}" />
                    <MenuItem Header="{x:Static Resources:UIStringTable.TopAndBottomDoubleBorder}"  oui:RibbonElement.Icon="{media:SmallImage BordersTopBottomDouble}" Command="{x:Static ssui:BorderCommands.SetTopAndBottomBorders}" CommandParameter="{x:Static ss:BorderStyle.Double}" />
                    <Separator/>
                    <MenuItem Header="{x:Static Resources:UIStringTable.MoreBorders}" Command="{x:Static ssui:SpreadsheetCommands.FormatCells}" CommandParameter="Borders"/>

                </MenuItem>
            </Menu>
            <Menu >
                <Menu.Resources>
                    <CollectionViewSource Source="{Binding Converter={x:Static Internals:SpreadsheetConverters.StandardFillColorConverter}, Path=Workbook}" x:Key="colors">
                        <CollectionViewSource.GroupDescriptions>
                            <ssui:ColorGrouping/>
                        </CollectionViewSource.GroupDescriptions>
                    </CollectionViewSource>
                </Menu.Resources>
                <MenuItem Focusable="False" MinWidth="30" oui:RibbonElement.ControlState="Small" ItemTemplate="{StaticResource colorTemplate}"
                    ItemsSource="{Binding Source={StaticResource colors}}" oui:HighlightElement.HighlightedItemChanged="onBackgroundPreviewChanged" 
                          Command="{x:Static oui:OfficeApplicationCommands.SetBackground}" Click="onParentMenuItemClick"  >
                    <MenuItem.CommandParameter>
                        <ss:RgbColor Color="Yellow"></ss:RgbColor>
                    </MenuItem.CommandParameter>
                    <MenuItem.Header>
                        <Grid  >
                            <Image Source="/OpenLS.Media;component/ShapeFillPickColorClassic.png" Margin ="0 3 0 -3" Width="16" Height="16"/>
                            <Rectangle VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="4" Width="13" Margin="0 3 0 -3"
                                       >
                                <Rectangle.Fill>
                                    <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToBrushConverter}">
                                        <Binding RelativeSource="{RelativeSource AncestorType={x:Type MenuItem}}" Path="CommandParameter"/>
                                        <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                        <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                    </MultiBinding>
                                </Rectangle.Fill>
                            </Rectangle>
                        </Grid>
                    </MenuItem.Header>

                    <MenuItem.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel MaxWidth="180"/>
                        </ItemsPanelTemplate>
                    </MenuItem.ItemsPanel>
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Command" Value="{x:Static oui:OfficeApplicationCommands.SetBackground}"/>
                            <Setter Property="CommandParameter" Value="{Binding}"/>
                            <Setter Property="Margin" Value="1"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type MenuItem}">
                                        <Border BorderBrush="Gray" BorderThickness="1" Name="extBorder" Margin="{TemplateBinding Margin}">
                                            <Grid>
                                                <ContentPresenter x:Name="Header" Margin="0"
                                            VerticalAlignment="Center" ContentSource="Header" />
                                                <Border BorderBrush="Transparent" BorderThickness="1"  Name="intBorder">
                                                </Border>
                                            </Grid>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsHighlighted" Value="True">
                                                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                                                <Setter Property="BorderBrush" Value="Orange" TargetName="extBorder" />
                                                <Setter Property="BorderBrush" Value="White" TargetName="intBorder" />
                                                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                    <MenuItem.GroupStyle>
                        <GroupStyle HidesIfEmpty="False">
                            <GroupStyle.HeaderTemplate>
                                <HierarchicalDataTemplate DataType="{x:Type CollectionViewGroup}">
                                    <Border BorderThickness="0 0 0 1" BorderBrush="#FFC5C5C5">
                                        <TextBlock Text="{Binding Name}" Background="#FFDDE7EE" FontWeight="Bold"/>
                                    </Border>
                                </HierarchicalDataTemplate>
                            </GroupStyle.HeaderTemplate>
                        </GroupStyle>
                    </MenuItem.GroupStyle>
                </MenuItem>
            </Menu>
            <Menu>
                <Menu.Resources>
                    <CollectionViewSource Source="{Binding Converter={x:Static Internals:SpreadsheetConverters.StandardTextColorConverter}, Path=Workbook}" x:Key="colors">
                        <CollectionViewSource.GroupDescriptions>
                            <ssui:ColorGrouping/>
                        </CollectionViewSource.GroupDescriptions>
                    </CollectionViewSource>
                </Menu.Resources>
                <MenuItem Focusable="False" Tag="Small" oui:RibbonElement.ControlState="Small" 
                          ItemTemplate="{StaticResource colorTemplate}"
                    ItemsSource="{Binding Source={StaticResource colors}}"
                          oui:HighlightElement.HighlightedItemChanged="onForegroundPreviewChanged"
                          Command="{x:Static oui:OfficeApplicationCommands.SetForeground}" Click="onParentMenuItemClick"  >
                    <MenuItem.CommandParameter>
                        <ss:RgbColor Color="Black"></ss:RgbColor>
                    </MenuItem.CommandParameter>
                    <MenuItem.Header>
                        <Grid>
                            <TextBlock VerticalAlignment="Top" Width="16" Height="16" Margin ="0 3 0 -3" TextAlignment="Center">A</TextBlock>
                            <Rectangle VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="4" Width="12" Margin="-1 3 0 -3">
                                <Rectangle.Fill>
                                    <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToBrushConverter}">
                                        <Binding RelativeSource="{RelativeSource AncestorType={x:Type MenuItem}}" Path="CommandParameter"/>
                                        <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                        <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                        <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                    </MultiBinding>
                                </Rectangle.Fill>
                            </Rectangle>
                        </Grid>
                    </MenuItem.Header>

                    <MenuItem.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel MaxWidth="180"/>
                        </ItemsPanelTemplate>
                    </MenuItem.ItemsPanel>
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Command" Value="{x:Static oui:OfficeApplicationCommands.SetForeground}"/>
                            <Setter Property="CommandParameter" Value="{Binding}"/>
                            <Setter Property="Margin" Value="1"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type MenuItem}">
                                        <Border BorderBrush="Gray" BorderThickness="1" Name="extBorder"
                              Margin="{TemplateBinding Margin}">
                                            <Grid>
                                                <ContentPresenter x:Name="Header" Margin="0"
                                            VerticalAlignment="Center" ContentSource="Header" />
                                                <Border BorderBrush="Transparent" BorderThickness="1"  Name="intBorder">
                                                </Border>
                                            </Grid>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsHighlighted" Value="True">
                                                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                                                <Setter Property="BorderBrush" Value="Orange" TargetName="extBorder" />
                                                <Setter Property="BorderBrush" Value="White" TargetName="intBorder" />
                                                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True"/>

                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                            <!--<Setter Property="Height" Value="20"/>
                        <Setter Property="Width" Value="20"/> -->
                        </Style>
                    </MenuItem.ItemContainerStyle>
                    <!-- <MenuItem.ItemTemplate>
                            <HierarchicalDataTemplate DataType="{x:Type ss:SpreadsheetColor}">
                                <Rectangle Height="12" Width="12" Name="r">
                                    <Rectangle.Fill>
                                        <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToBrushConverter}">
                                            <Binding/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                        </MultiBinding>
                                    </Rectangle.Fill>
                                </Rectangle>

                            </HierarchicalDataTemplate>
                        </MenuItem.ItemTemplate> -->
                    <MenuItem.GroupStyle>
                        <GroupStyle HidesIfEmpty="False">
                            <GroupStyle.HeaderTemplate>
                                <HierarchicalDataTemplate DataType="{x:Type CollectionViewGroup}">
                                    <Border BorderThickness="0 0 0 1" BorderBrush="#FFC5C5C5">
                                        <TextBlock Text="{Binding Name}" Background="#FFDDE7EE" FontWeight="Bold"/>
                                    </Border>
                                </HierarchicalDataTemplate>
                            </GroupStyle.HeaderTemplate>

                        </GroupStyle>
                    </MenuItem.GroupStyle>

                </MenuItem>

            </Menu>

        </oui:FlowPanel>

    </oui:Group>
    <oui:Group DockPanel.Dock="Left" Header="{x:Static Resources:UIStringTable.Alignment}"
               Command="{x:Static ssui:SpreadsheetCommands.FormatCells}" CommandParameter="Alignment"
               MediumStatePriority="4" SmallStatePriority="7" CollapsedStatePriority="15">
        <oui:FlowPanel oui:RibbonElement.SmallGroupStyle="{x:Static oui:FlowPanel.NoMarginStyle}">
            <oui:Box>
                <ToggleButton VerticalAlignment ="Top" Command ="{x:Static EditingCommands.AlignLeft}" IsChecked="{Binding Path=Selection.HorizontalAlignment, Converter={x:Static Internals:SpreadsheetConverters.IsLeft}}" >
                    <Canvas Width="16" Height="16" Margin="1 1 0 0">
                        <Path  Data="M 0,0 L 13,0 M 0,2 L 9,2 M 0,4 L 13,4 M 0,6 L 9,6 M 0,8 L 13,8 M 0,10 L 9,10" Fill='Black' Stroke='Black'/>
                    </Canvas>
                </ToggleButton>
                <ToggleButton Command ="{x:Static EditingCommands.AlignCenter}" IsChecked="{Binding Path=Selection.HorizontalAlignment, Converter={x:Static Internals:SpreadsheetConverters.IsHCenter}}" >
                    <Canvas Width="16" Height="16"  Margin="1 1 0 0">
                        <Path Data="M 0,0 L 13,0 M 2,2 L 11,2 M 0,4 L 13,4 M 2,6 L 11,6 M 0,8 L 13,8 M 2,10 L 11,10" Fill='Black' Stroke='Black'/>
                    </Canvas>
                </ToggleButton>
                <ToggleButton Command ="{x:Static EditingCommands.AlignRight}" IsChecked="{Binding Path=Selection.HorizontalAlignment, Converter={x:Static Internals:SpreadsheetConverters.IsRight}}">
                    <Canvas Width="16" Height="16"  Margin="1 1 0 0">
                        <Path Data="M 0,0 L 13,0 M 4,2 L 13,2 M 0,4 L 13,4 M 4,6 L 13,6 M 0,8 L 13,8 M 4,10 L 13,10" Fill='Black' Stroke='Black'/>
                    </Canvas>
                </ToggleButton>
            </oui:Box>
            <!--
                  </StackPanel>
                </Border> -->
            <oui:Box oui:RibbonElement.ControlState='Small'>

                <Button Command="{x:Static EditingCommands.DecreaseIndentation}">
                    <!--  <Image Stretch="Uniform"  Source="/OpenLS.Media;component/DecreaseIndentation.png"/> -->
                </Button>
                <Button Command="{x:Static EditingCommands.IncreaseIndentation}">
                    <!--   <Image Stretch="Uniform" Source="/OpenLS.Media;component/IncreaseIndentation.png"/> -->
                </Button>
            </oui:Box>
            <ToggleButton Margin ="3 0 0 0" Command ='{x:Static ssui:SpreadsheetEditingCommands.ToggleTextWrapping}' Content='{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}'
                      IsChecked='{Binding Selection.TextWrapping, Converter={x:Static Internals:SpreadsheetConverters.IsTextWrapping}}'
                      oui:RibbonElement.ControlState='Medium'
                  oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.MediumControlStyle}"
                    oui:RibbonElement.SmallGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}">
                <!--<ToggleButton.Content>
                <StackPanel Orientation ="Horizontal" >
                  <Image Width="16" Height="16" Source="/OpenLS.Media;component/WrapText.png" VerticalAlignment="Top"/>
                  <TextBlock VerticalAlignment="Top" TextElement.Foreground="{DynamicResource {ssui:OfficeUIResourceKey TextForeground}}">Wrap text</TextBlock>
                </StackPanel>
              </ToggleButton.Content> -->
            </ToggleButton>

            <oui:Box>

                <ToggleButton Command  ="{x:Static ssui:SpreadsheetEditingCommands.VerticalAlignTop}" IsChecked="{Binding Path=Selection.VerticalAlignment, Converter={x:Static Internals:SpreadsheetConverters.IsTop}}">
                    <Canvas Width="16" Height="16" Margin="1 1 0 0">
                        <Path Canvas.Top='1' Data="M 0,0 L 13,0 M 2,2 L 11,2 M 0,4 L 13,4 M 2,6 L 11,6" Fill='Black' Stroke='Black'/>
                    </Canvas>
                </ToggleButton>
                <ToggleButton Command ="{x:Static ssui:SpreadsheetEditingCommands.VerticalAlignCenter}" IsChecked="{Binding Path=Selection.VerticalAlignment, Converter={x:Static Internals:SpreadsheetConverters.IsVCenter}}">
                    <Canvas Width="16" Height="16" Margin="1 1 0 0">
                        <Path  Canvas.Top='3' Data="M 0,0 L 13,0 M 2,2 L 11,2 M 0,4 L 13,4 M 2,6 L 11,6" Fill='Black' Stroke='Black'/>
                    </Canvas>
                </ToggleButton>
                <ToggleButton
                        Command ="{x:Static ssui:SpreadsheetEditingCommands.VerticalAlignBottom}" IsChecked="{Binding Path=Selection.VerticalAlignment, Converter={x:Static Internals:SpreadsheetConverters.IsBottom}}">
                    <Canvas Width="16" Height="16"  Margin="1 1 0 0">
                        <Path Canvas.Top='5' Data="M 0,0 L 13,0 M 2,2 L 11,2 M 0,4 L 13,4 M 2,6 L 11,6" Fill='Black' Stroke='Black'/>
                    </Canvas>
                </ToggleButton>
            </oui:Box>
            <Menu>
                <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.MergeCellsAndCenter}"
                    oui:RibbonElement.ControlState="Medium"
                    oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.MediumControlStyle}"
                    oui:RibbonElement.SmallGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}">
                    <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.MergeCellsAndCenter}"  />
                    <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.MergeCellsAcross}"  />
                    <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.MergeCells}"  />
                    <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.UnmergeCells}"  />
                </MenuItem>
            </Menu>
        </oui:FlowPanel>
    </oui:Group>
    <oui:Group DockPanel.Dock="Left" Header="{x:Static Resources:UIStringTable.Number}"
               Command="{x:Static ssui:SpreadsheetCommands.FormatCells}"
               MediumStatePriority="9" CollapsedStatePriority="14">

        <oui:FlowPanel Tag="numbers" oui:RibbonElement.MediumGroupStyle="{x:Static oui:FlowPanel.NoMarginStyle}">
            <!--  <ComboBox Focusable="False" ItemsSource="{x:Static ss:FormatManager.BuiltInFormats}" SelectionChanged ="OnFormatChanged"/> -->
            <ComboBox Focusable="False" Text="{Binding Path=ActiveCell.Format.Category, Mode=OneWay}"
                  Tag="{Binding Path=ActiveCell.Format.Category, Mode=OneWay}" IsEditable="True" SelectionChanged="onFormatChanged"
                  HorizontalContentAlignment="Stretch"  Height="22">

                <ComboBox.Resources>
                    <Style TargetType="{x:Type StackPanel}">
                        <Setter Property="Background" Value="Transparent"/>
                    </Style>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType ="{x:Type Button}">
                                    <ContentPresenter/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="FontWeight" Value="Bold"/>
                        <Setter Property="FontSize" Value="12"/>
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"/>
                    </Style>
                    <Style TargetType="{x:Type TextBlock}" x:Key="aa">
                        <Setter Property="VerticalAlignment" Value="Center"/>
                        <Setter Property="FontFamily" Value="Baskerville Old Face"/>
                        <Setter Property="FontWeight" Value="Bold"/>
                        <Setter Property="FontSize" Value="16"/>
                        <Setter Property="ForceCursor" Value="True"/>
                        <Setter Property="Cursor" Value="Arrow"/>
                        <Setter Property="Width" Value="48"/>
                        <Setter Property="Height" Value="48"/>
                        <Setter Property="Background" Value="Transparent"/>
                        <Setter Property="Margin" Value="0"/>
                        <Setter Property="Padding" Value="0"/>
                    </Style>
                    <Style TargetType="{x:Type Image}">
                        <Setter Property="Width" Value="32"/>
                        <Setter Property="Height" Value="32"/>
                        <Setter Property="Margin" Value="8"/>
                    </Style>
                </ComboBox.Resources>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.General}"  >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource aa}">
                ABC<LineBreak/>123
                        </TextBlock>
                        <TextBlock  Text="{x:Static Resources:UIStringTable.General}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Number}"  >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock  Style="{StaticResource aa}" FontSize="18">
                123
                        </TextBlock>
                        <TextBlock  Text="{x:Static Resources:UIStringTable.Number}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Currency}" >
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/OpenLS.Media;component/FormatCurrency.png"/>
                        <TextBlock Text="{x:Static Resources:UIStringTable.Currency}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Accounting}" >
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/OpenLS.Media;component/FormatAccounting.png"/>
                        <TextBlock  Text="{x:Static Resources:UIStringTable.Accounting}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.ShortDate}" >
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/OpenLS.Media;component/FormatDate.png"/>
                        <TextBlock Text="{x:Static Resources:UIStringTable.ShortDate}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.LongDate}" >
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/OpenLS.Media;component/FormatDate.png"/>
                        <TextBlock  Text="{x:Static Resources:UIStringTable.LongDate}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Time}" >
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/OpenLS.Media;component/FormatTime.png"/>
                        <TextBlock  Text="{x:Static Resources:UIStringTable.Time}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Percent}" >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock  Style="{StaticResource aa}" FontSize="32">
                %
                        </TextBlock>
                        <TextBlock Text="{x:Static Resources:UIStringTable.Percentage}" />
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Fraction}" >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock   Style="{StaticResource aa}" FontSize="18">
                <Run BaselineAlignment="Superscript">1</Run>/<Run BaselineAlignment="Subscript">2</Run>
                        </TextBlock>
                        <TextBlock Text="{x:Static Resources:UIStringTable.Fraction}" ></TextBlock>
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Scientific}" >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource aa}" FontSize="18">
                10<Run BaselineAlignment="Superscript">2</Run>
                        </TextBlock>
                        <TextBlock Text="{x:Static Resources:UIStringTable.Scientific}" ></TextBlock>
                    </StackPanel>
                </Button>
                <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Text}" >
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource aa}" FontSize="18">
                ABC
                        </TextBlock>
                        <TextBlock Text="{x:Static Resources:UIStringTable.Text}"></TextBlock>
                    </StackPanel>
                </Button>
                <Separator/>
                <Button Command="{x:Static ssui:SpreadsheetCommands.FormatCells}" TextElement.Foreground="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"
                  Content="{x:Static Resources:UIStringTable.MoreNumberFormats}"></Button>
            </ComboBox>
            <oui:Box>
                <Menu Height="22">
                    <!---->
            <MenuItem Tag="Small" Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}"
                      CommandParameter="{x:Static Core:Formats.Currency}" Header="$"  >
              <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Currency}" Header="$" />
              <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static ss:StandardFormats.BritishPoundCurrencyFormat}" Header="£" />
              <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static ss:StandardFormats.EuroCurrencyFormat}" Header="€" />
              <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static ss:StandardFormats.JapaneseYenCurrencyFormat}" Header="¥" />
              <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static ss:StandardFormats.ChineseCurrencyFormat}" Header="￥" />
              <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static ss:StandardFormats.SwissCurrencyFormat}" Header="SFR." />
            </MenuItem>
          </Menu>
          <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Percent}" >%</Button>
          <Button Command="{x:Static ssui:SpreadsheetEditingCommands.SetFormat}" CommandParameter="{x:Static Core:Formats.Accounting}" FontFamily="Arial Black">,</Button>
        </oui:Box>
        <oui:Box  oui:RibbonElement.ControlState='Small'>
          <Button Command="{x:Static ssui:SpreadsheetCommands.IncreaseDecimal}"/>
          <Button Command="{x:Static ssui:SpreadsheetCommands.DecreaseDecimal}"/>
        </oui:Box>
      </oui:FlowPanel>
    </oui:Group>
    <oui:Group DockPanel.Dock="Left" Header="{x:Static Internals2:UIStringTable.Styles}" MediumStatePriority="5" SmallStatePriority="8"  CollapsedStatePriority="10">
        <StackPanel Orientation="Horizontal">
            <oui:RibbonElement.SmallGroupStyle>
                <Style TargetType="{x:Type StackPanel}" >
                    <Setter Property="Orientation" Value="Vertical" />
                </Style>
            </oui:RibbonElement.SmallGroupStyle>
            <StackPanel.Resources>
          <CollectionViewSource x:Key="stylesViewold" Source="{Binding Path=Workbook.BuiltInStyles}">
            <CollectionViewSource.GroupDescriptions>
              <ssui:CellStyleGrouping/>
            </CollectionViewSource.GroupDescriptions>
          </CollectionViewSource>
                <CollectionViewSource x:Key="stylesViewold2"  Source="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.Workbook).BuiltInStyles}">
            <CollectionViewSource.GroupDescriptions>
              <ssui:CellStyleGrouping/>
            </CollectionViewSource.GroupDescriptions>
          </CollectionViewSource>
            <CollectionViewSource x:Key="tableStylesView" Source="{x:Static  ssui:UITableStyles.Styles}">
            <CollectionViewSource.GroupDescriptions>
              <ssui:TableStyleGrouping/>
            </CollectionViewSource.GroupDescriptions>
          </CollectionViewSource>
                
            </StackPanel.Resources>
      <Menu oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.MediumControlStyle}">
          <Menu.Resources>
              <Style TargetType="{x:Type MenuItem}" x:Key="topMenuItemStyle" BasedOn="{StaticResource {x:Type MenuItem}}" >
                  <Setter Property="oui:RibbonElement.MediumGroupStyle">
                      <Setter.Value>
                          <Style TargetType="{x:Type MenuItem}">
                              <Setter Property="oui:RibbonElement.ControlState" Value="Large" />
                          </Style>                          
                      </Setter.Value>
                  </Setter>
                  <Setter Property="oui:RibbonElement.SmallGroupStyle">
                      <Setter.Value>
                          <Style TargetType="{x:Type MenuItem}">
                              <Setter Property="oui:RibbonElement.ControlState" Value="Medium" />
                          </Style>                          
                      </Setter.Value>
                  </Setter>
              </Style>
          </Menu.Resources>
        <MenuItem Header="{x:Static Resources:UIStringTable.ConditionalFormatting}"  Icon="{media:Image FontConditionalFormatting}" Style="{StaticResource topMenuItemStyle}"  >
            <MenuItem Header="{x:Static Resources:UIStringTable.HighlightCellRules}" Icon="{media:Image ConditionalFormattingHighlightCellsMenu}" >
                <MenuItem Header="{x:Static Resources:UIStringTable.GreaterThan}" Icon="{media:Image ConditionalFormattingHighlightGreaterThan}" Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                    <MenuItem.CommandParameter>
                    <ss:CellIsFormattingRule Operator="GreaterThan"/>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.LessThan}"  Icon="{media:Image ConditionalFormattingHighlightLessThan}"  Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                                        <MenuItem.CommandParameter>
                    <ss:CellIsFormattingRule Operator="LessThan"/>
                    </MenuItem.CommandParameter>
                </MenuItem>

                <MenuItem Header="{x:Static Resources:UIStringTable.Between}"  Icon="{media:Image ConditionalFormattingHighlightBetween}"  Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                                    <MenuItem.CommandParameter>
                    <ss:CellIsFormattingRule Operator="Between"/>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.EqualTo}"  Icon="{media:Image ConditionalFormattingHighlightEqualTo}"  Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                                    <MenuItem.CommandParameter>
                    <ss:CellIsFormattingRule Operator="Equal"/>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.TextThatContains}"  Icon="{media:Image ConditionalFormattingHighlightTextContaining}"  Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                                    <MenuItem.CommandParameter>
                    <ss:ContainsTextFormattingRule/>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.ADateOccuring}"  Icon="{media:Image ConditionalFormattingHilightDateOccuring}"  Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                    <MenuItem.CommandParameter>
                        <ss:TimePeriodFormattingRule />
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.DuplicateValues}"  Icon="{media:Image ConditionalFormattingHighlightDuplicateValues}"  Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                    <MenuItem.CommandParameter>
                        <ss:DuplicateValuesFormattingRule/>
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.UniqueValues}"  Icon="{media:Image ConditionalFormattingHighlightDuplicateValues}"  Command="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}">
                    <MenuItem.CommandParameter>
                        <ss:UniqueValuesFormattingRule/>
                    </MenuItem.CommandParameter>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="{x:Static Resources:UIStringTable.TopBottomRules}" Icon="{media:Image ConditionalFormattingTopNItems}" >
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
                        <Setter Property="Command" Value="{x:Static ssui:SpreadsheetCommands.CreateAndApplyRule}"/>
                    </Style>
                </MenuItem.ItemContainerStyle>
                <MenuItem Header="{x:Static Resources:UIStringTable.Top10Items}" Icon="{media:Image ConditionalFormattingTopNItems}" >
                    <MenuItem.CommandParameter>
                        <ss:Top10FormattingRule />
                    </MenuItem.CommandParameter>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.Top10Percent}" Icon="{media:Image ConditionalFormattingTopNPercent}">
                    <MenuItem.CommandParameter>
                        <ss:Top10FormattingRule Percent="True" />
                    </MenuItem.CommandParameter>                    
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.Bottom10Items}" Icon="{media:Image ConditionalFormattingBottomNItems}">
                    <MenuItem.CommandParameter>
                        <ss:Top10FormattingRule Bottom="True" />
                    </MenuItem.CommandParameter>                    
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.Bottom10Percent}" Icon="{media:Image ConditionalFormattingBottomNPercent}">
                    <MenuItem.CommandParameter>
                        <ss:Top10FormattingRule Bottom="True" Percent="True" />
                    </MenuItem.CommandParameter>                    
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.AboveAverage}" Icon="{media:Image ConditionalFormattingAboveAverage}">
                    <MenuItem.CommandParameter>
                        <ss:AboveAverageFormattingRule AboveAverage="True"/>
                    </MenuItem.CommandParameter>                                        
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.BelowAverage}" Icon="{media:Image ConditionalFormattingBelowAverage}" >
                    <MenuItem.CommandParameter>
                        <ss:AboveAverageFormattingRule AboveAverage="False" />
                    </MenuItem.CommandParameter>                                        
                </MenuItem>
            </MenuItem>
            <Separator/>
            <MenuItem Header="{x:Static Resources:UIStringTable.DataBars}" Icon="{media:Image FontConditionalFormatting}"  ItemsSource="{x:Static ssui:ConditionalFormattingRules.DataBars}"
                      oui:HighlightElement.HighlightedItemChanged="onConditionalFormattingChanged" >
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource  {x:Type MenuItem}}"> 
                        <Setter Property="Command" Value="{x:Static ssui:SpreadsheetCommands.ApplyRule}"/>
                        <Setter Property="CommandParameter" Value="{Binding}"/>
                    </Style>
                </MenuItem.ItemContainerStyle>
                <MenuItem.ItemTemplate>
                    <DataTemplate DataType="{x:Type ss:DataBarFormattingRule}">
                        <Path Height="32" Width="32" Data="M0,0 L12,0 L12,4 L0,4 Z M0,6 L18,6 L18,10 L0,10 Z M0,12 L8,12 L8,16 L0,16 Z M0,18 L22,18 L22,22 L0,22 Z M0,24 L16,24 L16,28 L0,28 Z">
                            <Path.Fill>
                                <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ColorToBrushConverter}">
                                    <Binding Path="Color" />
                                    <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                </MultiBinding>
                            </Path.Fill>
                        </Path>
                    </DataTemplate>
                </MenuItem.ItemTemplate>
                <MenuItem.ItemsPanel><ItemsPanelTemplate><WrapPanel Width="230"></WrapPanel></ItemsPanelTemplate></MenuItem.ItemsPanel>
            </MenuItem>
            <MenuItem Header="{x:Static Resources:UIStringTable.ColorScales}" Icon="{media:Image FontConditionalFormatting}" oui:HighlightElement.HighlightedItemChanged="onConditionalFormattingChanged"
                      ItemsSource="{x:Static ssui:ConditionalFormattingRules.ColorScales}">
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource  {x:Type MenuItem}}"> 
                        <Setter Property="Command" Value="{x:Static ssui:SpreadsheetCommands.ApplyRule}"/>
                        <Setter Property="CommandParameter" Value="{Binding}"/>
                    </Style>
                </MenuItem.ItemContainerStyle>
                <MenuItem.ItemTemplate>
                    <DataTemplate DataType="{x:Type ss:ColorScaleFormattingRule}">
                        <Rectangle Height="32" Width="32">
                            <Rectangle.Fill>
                                <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.ScaleColorsToBrushConverter}">
                                    <Binding Path="Colors" />
                                    <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                </MultiBinding>
                            </Rectangle.Fill>
                        </Rectangle>
                    </DataTemplate>
                </MenuItem.ItemTemplate>
                <MenuItem.ItemsPanel><ItemsPanelTemplate><WrapPanel Width="270" ></WrapPanel></ItemsPanelTemplate></MenuItem.ItemsPanel>
            </MenuItem>
            <Separator/>
            <MenuItem oui:RibbonElement.ControlState="Medium" Command="{x:Static ssui:SpreadsheetCommands.NewRule}" />
            <MenuItem oui:RibbonElement.ControlState="Small" Header="{x:Static Resources:UIStringTable.ClearRules}"  Icon="{media:SmallImage ConditionalFormattingClearMenu}" >
                <MenuItem oui:RibbonElement.ControlState="Medium"  Command="{x:Static ssui:SpreadsheetCommands.ClearSelectionRules}" />
                <MenuItem oui:RibbonElement.ControlState="Medium"  Command="{x:Static ssui:SpreadsheetCommands.ClearSheetRules}" />
                <MenuItem oui:RibbonElement.ControlState="Medium"  Command="{x:Static ssui:SpreadsheetCommands.ClearTableRules}" />

            </MenuItem>
            <MenuItem oui:RibbonElement.ControlState="Medium" Command="{x:Static ssui:SpreadsheetCommands.ManageRules}" />
        </MenuItem>
        <MenuItem  Header="{x:Static Resources:UIStringTable.FormatAsTable}" ItemsSource="{Binding Source={StaticResource tableStylesView}}" oui:HighlightElement.HighlightedItemChanged="onTableStylePreviewChanged" Icon="{media:Image FormatAsTableGallery}" Style="{StaticResource topMenuItemStyle}">
            <MenuItem.ItemContainerStyle>              
            <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
              <Setter Property="Command" Value="{x:Static ssui:SpreadsheetCommands.FormatAsStandardTable}"/>
              <Setter Property="CommandParameter" Value="{Binding}"/>
              <Setter Property="Padding" Value="1"/>
              <Setter Property="Template" Value="{StaticResource {x:Static oui:ComponentKeys.SubmenuItemNoPaddingTemplateKey}}"/>
              <Style.Triggers>
                <Trigger Property="Role" Value="SubmenuItem">
                  <Setter Property ="Template" Value ="{StaticResource {x:Static oui:ComponentKeys.SubmenuItemNoPaddingTemplateKey}}"/>
                  <Setter Property="DockPanel.Dock" Value="Top" />
                </Trigger>

              </Style.Triggers>
            </Style>
                          </MenuItem.ItemContainerStyle>
          <MenuItem.GroupStyle>
            <GroupStyle HidesIfEmpty="False">
              <GroupStyle.HeaderTemplate>
                <HierarchicalDataTemplate DataType="{x:Type CollectionViewGroup}">
                  <Border BorderThickness="0 0 0 1" BorderBrush="#FFC5C5C5">
                    <TextBlock Text="{Binding Name}" Background="#FFDDE7EE" FontWeight="Bold"/>
                  </Border>
                </HierarchicalDataTemplate>
              </GroupStyle.HeaderTemplate>
            </GroupStyle>
          </MenuItem.GroupStyle>
          <MenuItem.ItemsPanel>
            <ItemsPanelTemplate>
              <WrapPanel MaxWidth="500"/>
            </ItemsPanelTemplate>
          </MenuItem.ItemsPanel>

        </MenuItem>
            </Menu>
            <Grid DataContext="{Binding Workbook}">
                 <oui:RibbonElement.LargeGroupStyle>
                        <Style TargetType="{x:Type oui:Gallery}">
                            <Setter Property="MaxColumns"  Value="2"></Setter>
                        </Style>
                    </oui:RibbonElement.LargeGroupStyle>
                    <oui:RibbonElement.MediumGroupStyle>
                        <Style TargetType="{x:Type oui:Gallery}">
                            <Setter Property="oui:RibbonElement.ControlState"  Value="Medium"></Setter>
                        </Style>
                    </oui:RibbonElement.MediumGroupStyle>
                    <oui:RibbonElement.SmallGroupStyle>
                        <Style TargetType="{x:Type oui:Gallery}">
                            <Setter Property="oui:RibbonElement.ControlState"  Value="Small"></Setter>
                        </Style>
                    </oui:RibbonElement.SmallGroupStyle>
                   
                <Grid.Resources>
                    <CollectionViewSource x:Key="stylesView" Source="{Binding Path=BuiltInStyles}">
                                <CollectionViewSource.GroupDescriptions>
                                    <ssui:CellStyleGrouping/>
                                </CollectionViewSource.GroupDescriptions>
                            </CollectionViewSource>

                    </Grid.Resources>
          <oui:Gallery Focusable="False" Header="{x:Static Resources:UIStringTable.CellStyles}" ItemsSource="{Binding Source={StaticResource stylesView}}"
                       oui:HighlightElement.HighlightedItemChanged="onCellStylePreviewChanged" Icon="{media:Image CellStyleGallery}"
                       SelectionChanged="onStyleChanged" DropDownWidth="670" DropDownHeight="400">

                    <oui:RibbonElement.LargeGroupStyle>
                        <Style TargetType="{x:Type oui:Gallery}">
                            <Setter Property="MaxColumns"  Value="2"></Setter>
                        </Style>
                    </oui:RibbonElement.LargeGroupStyle>
                    <oui:RibbonElement.MediumGroupStyle>
                        <Style TargetType="{x:Type oui:Gallery}">
                            <Setter Property="oui:RibbonElement.ControlState"  Value="Medium"></Setter>
                        </Style>
                    </oui:RibbonElement.MediumGroupStyle>
                    <oui:RibbonElement.SmallGroupStyle>
                        <Style TargetType="{x:Type oui:Gallery}">
                            <Setter Property="oui:RibbonElement.ControlState"  Value="Small"></Setter>
                        </Style>
                    </oui:RibbonElement.SmallGroupStyle>
                    </oui:Gallery>
                    </Grid>
                    </StackPanel>
    </oui:Group>
    <oui:Group DockPanel.Dock="Left" Header="{x:Static Resources:UIStringTable.Cells}" MediumStatePriority="3" CollapsedStatePriority="13">

        <Menu oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.MediumControlStyle}">
            <MenuItem Header="{x:Static Internals2:UIStringTable.Insert}" Command="{x:Static ssui:SpreadsheetCommands.InsertCells}" 
                  CommandParameter="{x:Static ss:CellMoveOrientationHint.Vertical}">
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.InsertCells}" oui:RibbonElement.ControlState="Medium"/>
                <Separator/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.InsertRow}" oui:RibbonElement.ControlState="Medium"/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.InsertColumn}" oui:RibbonElement.ControlState="Small" >
                    <MenuItem.Icon>
                        <Image Source="/OpenLS.Media;component/TableRowsInsert.png">
                            <Image.RenderTransform>
                                <RotateTransform Angle="90" CenterX="8" CenterY="8"/>
                            </Image.RenderTransform>
                        </Image>
                    </MenuItem.Icon>

                </MenuItem>
                <Separator/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.InsertWorksheet}" oui:RibbonElement.ControlState="Medium"/>
            </MenuItem>
            <MenuItem Header="{x:Static Resources:UIStringTable.Delete}" Command="{x:Static ssui:SpreadsheetCommands.DeleteCells}" CommandParameter="{x:Static ss:CellMoveOrientationHint.Vertical}">
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.DeleteCells}" oui:RibbonElement.ControlState="Medium"/>
                <Separator/>
                <MenuItem Command ="{x:Static ssui:SpreadsheetCommands.DeleteRows}" oui:RibbonElement.ControlState="Medium"/>
                <MenuItem Command ="{x:Static ssui:SpreadsheetCommands.DeleteColumns}"  oui:RibbonElement.ControlState="Medium"/>
                <Separator/>
                <MenuItem Command ="{x:Static ssui:SpreadsheetCommands.DeleteSheet}" oui:RibbonElement.ControlState="Medium" />
            </MenuItem>
            <MenuItem Header="{x:Static Resources:UIStringTable.Format}" Icon="{media:Image FormatCellsMenu}" >
                <MenuItem.Resources>
                    <CollectionViewSource Source="{Binding Converter={x:Static Internals:SpreadsheetConverters.StandardFillColorConverter}, Path=Workbook}" x:Key="colors">
                        <CollectionViewSource.GroupDescriptions>
                            <ssui:ColorGrouping/>
                        </CollectionViewSource.GroupDescriptions>
                    </CollectionViewSource>

                </MenuItem.Resources>

                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.SetRowHeight}" oui:RibbonElement.ControlState="Medium"/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.AutoFitRowHeight}" />
                <Separator/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.SetColumnWidth}" oui:RibbonElement.ControlState="Medium"/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.AutoFitColumnWidth}"  />
                <!--
                <MenuItem Header="{x:Static Internals:UIStringTable.DefaultWidth}"/>
                -->
                <Separator/>
                <MenuItem Header="{x:Static Resources:UIStringTable.HideAndUnhide}">
                    <MenuItem Command="{x:Static ssui:SpreadsheetCommands.HideSheet}"  CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.Worksheet)}"/>
                    <MenuItem Command="{x:Static ssui:SpreadsheetCommands.HideColumns}" />
                    <MenuItem Command="{x:Static ssui:SpreadsheetCommands.HideRows}" />
                    <Separator/>
                    <MenuItem Command="{x:Static ssui:SpreadsheetCommands.UnhideColumns}" />
                    <MenuItem Command="{x:Static ssui:SpreadsheetCommands.UnhideRows}" />
                </MenuItem>
                <!--
                    <MenuItem Header="{x:Static Internals:UIStringTable.Rename}"/>
                -->
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.MoveOrCopySheet}"/>
                <MenuItem Header="{x:Static Resources:UIStringTable.TabColor}" ItemsSource="{Binding Source={StaticResource colors}}"  ItemTemplate="{StaticResource colorTemplate}" >

                    <MenuItem.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel MaxWidth="180"/>
                        </ItemsPanelTemplate>
                    </MenuItem.ItemsPanel>
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Command" Value="{x:Static ssui:SpreadsheetCommands.SetTabColor}"/>
                            <Setter Property="CommandParameter" Value="{Binding}"/>
                            <Setter Property="Margin" Value="1"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type MenuItem}">
                                        <Border BorderBrush="Gray" BorderThickness="1" Name="extBorder" Margin="{TemplateBinding Margin}">
                                            <Grid>
                                                <ContentPresenter x:Name="Header" Margin="0"
                                            VerticalAlignment="Center" ContentSource="Header" />
                                                <Border BorderBrush="Transparent" BorderThickness="1"  Name="intBorder">
                                                </Border>
                                            </Grid>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsHighlighted" Value="True">
                                                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                                                <Setter Property="BorderBrush" Value="Orange" TargetName="extBorder" />
                                                <Setter Property="BorderBrush" Value="White" TargetName="intBorder" />
                                                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                    <MenuItem.GroupStyle>
                        <GroupStyle HidesIfEmpty="False">
                            <GroupStyle.HeaderTemplate>
                                <HierarchicalDataTemplate DataType="{x:Type CollectionViewGroup}">
                                    <Border BorderThickness="0 0 0 1" BorderBrush="#FFC5C5C5">
                                        <TextBlock Text="{Binding Name}" Background="#FFDDE7EE" FontWeight="Bold"/>
                                    </Border>
                                </HierarchicalDataTemplate>
                            </GroupStyle.HeaderTemplate>
                        </GroupStyle>
                    </MenuItem.GroupStyle>
                </MenuItem>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.ProtectSheet}" oui:RibbonElement.ControlState="Small"/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.ToggleCellLock}" IsChecked="{Binding Path=Selection.IsLocked}"/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.FormatCells}"  />
            </MenuItem>
        </Menu>
    </oui:Group>
    <oui:Group DockPanel.Dock="Left" Header="{x:Static Internals2:UIStringTable.Editing}" MediumStatePriority="2" SmallStatePriority="11" CollapsedStatePriority="Never">

        <!--  <StackPanel Orientation="Horizontal">
            <StackPanel Orientation="Vertical"> -->
        <Menu oui:RibbonElement.ControlState ="Medium" >
            <MenuItem Command="{x:Static ssui:SpreadsheetCommands.AutoSum}" CommandParameter="SUM"
                   oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}"
                  oui:RibbonElement.ControlState="Medium" >
                <MenuItem.Icon>
                    <TextBlock FontFamily="Symbol" FontWeight="UltraBold" Width="16" Height="16" HorizontalAlignment="Center" TextAlignment="Center">S</TextBlock>
                </MenuItem.Icon>
                <MenuItem Header="{x:Static Resources:UIStringTable.Sum}"  Command="{x:Static ssui:SpreadsheetCommands.AutoSum}" >
                    <MenuItem.Icon>
                        <TextBlock FontFamily="Symbol" FontWeight="UltraBold"  Width="16"  Height="16"  HorizontalAlignment="Center" TextAlignment="Center">S</TextBlock>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.Average}"  Command="{x:Static ssui:SpreadsheetCommands.AutoSum}" CommandParameter="AVERAGE" />
                <MenuItem Header="{x:Static Resources:UIStringTable.CountNumber}"  Command="{x:Static ssui:SpreadsheetCommands.AutoSum}" CommandParameter="COUNT" />
                <MenuItem Header="{x:Static Resources:UIStringTable.Min}" Command="{x:Static ssui:SpreadsheetCommands.AutoSum}" CommandParameter="MIN" />
                <MenuItem Header="{x:Static Resources:UIStringTable.Max}" Command="{x:Static ssui:SpreadsheetCommands.AutoSum}" CommandParameter="Max" />
            </MenuItem>
            <MenuItem Header="{x:Static Resources:UIStringTable.Fill}" oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}"
                  oui:RibbonElement.ControlState="Medium"  Icon="{media:Image FillDown}" >
                <MenuItem Header="{x:Static Resources:UIStringTable.Down}" Command="{x:Static ssui:SpreadsheetCommands.Fill}" CommandParameter="{x:Static ss:NavigationDirection.Down}" Icon="{media:Image FillDown}" />
                <MenuItem Header="{x:Static Internals2:UIStringTable.Right}" Command="{x:Static ssui:SpreadsheetCommands.Fill}" CommandParameter="{x:Static ss:NavigationDirection.Right}" Icon="{media:Image FillRight}" />
                <MenuItem Header="{x:Static Resources:UIStringTable.Up}" Command="{x:Static ssui:SpreadsheetCommands.Fill}" CommandParameter="{x:Static ss:NavigationDirection.Up}" Icon="{media:Image FillUp}" />
                <MenuItem Header="{x:Static Internals2:UIStringTable.Left}" Command="{x:Static ssui:SpreadsheetCommands.Fill}"  CommandParameter="{x:Static ss:NavigationDirection.Left}" Icon="{media:Image FillLeft}" />
                <MenuItem Header="{x:Static Resources:UIStringTable.AcrossWorksheets}" />
                <MenuItem Header="{x:Static Resources:UIStringTable.Series__}" />
                <MenuItem Header="{x:Static Resources:UIStringTable.Justify}" />
            </MenuItem>
            <MenuItem Header="{x:Static Resources:UIStringTable.Clear}"
                  oui:RibbonElement.MediumGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}"
                  oui:RibbonElement.ControlState="Medium"  Icon="{media:Image Clear}" >
                <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.ClearAll}"  Icon="{media:Image Clear}" >

                </MenuItem>
                <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.ClearFormats}"  Icon="{media:Image ClearFormats}" >

                </MenuItem>
                            <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.ClearContents}"  />
                            <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.ClearComments}"  />
                            <MenuItem Command="{x:Static ssui:SpreadsheetEditingCommands.ClearHyperlinks}"  />
                            <!--<MenuItem Command="{x:Static ssui:SpreadsheetCommands.DeleteComment}"/> -->
            </MenuItem>
            <MenuItem oui:RibbonElement.ControlState ="Large" Header="{x:Static Resources:UIStringTable.SortAndFilter}" oui:RibbonElement.SmallGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}" Icon="{media:Image SortFilterMenu}" >
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.SortUp}" oui:RibbonElement.ControlState="Small"  Icon="{media:Image SortUp}" >
                </MenuItem>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.SortDown}" oui:RibbonElement.ControlState="Small"  Icon="{media:Image SortDown}" >
                </MenuItem>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.CustomSort}" oui:RibbonElement.ControlState="Small"  Icon="{media:Image SortDialog}" >
                </MenuItem>
                <Separator/>
                <MenuItem oui:RibbonElement.ControlState="Small" Command="{x:Static ssui:SpreadsheetCommands.ApplyFilter}" Icon="{media:Image FilterToggleFilter}" >
                </MenuItem>
                <MenuItem oui:RibbonElement.ControlState="Small" Command="{x:Static ssui:SpreadsheetCommands.ClearFilter}" Icon="{media:Image FilterClearAllFilters}" >
                </MenuItem>
                <MenuItem oui:RibbonElement.ControlState="Small" Command="{x:Static ssui:SpreadsheetCommands.ReApplyFilter}" Icon="{media:Image FilterReapply}" >
                </MenuItem>
            </MenuItem>
            <MenuItem oui:RibbonElement.ControlState ="Large" Header="{x:Static Resources:UIStringTable.FindAndSelect}" oui:RibbonElement.SmallGroupStyle="{x:Static oui:RibbonElement.SmallControlStyle}" Icon="{media:Image FindDialog}" >
                <MenuItem Header="{x:Static Internals2:UIStringTable.Find__}" Command="{x:Static ApplicationCommands.Find}" oui:RibbonElement.ControlState="Small"   Icon="{media:Image FindDialog}" >
                </MenuItem>
                <MenuItem Header="{x:Static Internals2:UIStringTable.Replace__}" Command="{x:Static ApplicationCommands.Replace}" oui:RibbonElement.ControlState="Small"   Icon="{media:Image ReplaceDialog}" >
                </MenuItem>
                <MenuItem Header="{x:Static Internals2:UIStringTable.GoTo__}" oui:RibbonElement.ControlState="Small"  Icon="{media:Image Goto}" >
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.GoToSpecial}"/>
                <Separator/>
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.FindFormulas}" />
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.FindComments}" />
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.FindConditionalFormatting}" />
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.FindConstants}" />
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.FindConstants}" />
                <MenuItem Command="{x:Static ssui:SpreadsheetCommands.FindDataValidation}" />
                <Separator/>

                <MenuItem Header="{x:Static Resources:UIStringTable.SelectObjects}" oui:RibbonElement.ControlState="Small"  Icon="{media:Image SelectRecord}" >
                </MenuItem>
                <MenuItem Header="{x:Static Resources:UIStringTable.SelectionPane}" oui:RibbonElement.ControlState="Small"  Icon="{media:Image SelectionPane}" >
                </MenuItem>
            </MenuItem>
        </Menu>
    </oui:Group>
</oui:GroupPanel>